<?php

    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    {

        protected function _initFrontController()
        {
            $front = Zend_Controller_Front::getInstance();

            $front->setControllerDirectory(array(
                'default' => APPLICATION_PATH . '/controllers',
            ));
            $front->registerPlugin(new Application_Plugin_SetApp());
            $front->registerPlugin(new Application_Plugin_SocialPlugin());
            $front->throwExceptions(TRUE);
            return $front;
        }

        protected function _initMyActionHelpers()
        {
            $this->bootstrap('frontController');
            //Zend_Controller_Action_HelperBroker::addPrefix('Application_Controller_Helper');
            Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/controllers/helpers', 'Application_Controller_Helper');
            $signup = Zend_Controller_Action_HelperBroker::getStaticHelper('Signup');
            Zend_Controller_Action_HelperBroker::addHelper($signup);
        }

        protected function _initDB()
        {
            if ($_SERVER["REMOTE_ADDR"] == "127.0.0.1")
                $dbConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/db-local.ini', "production");
            else
                $dbConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/db-server.ini', "production");

            $dbConfig = $dbConfig->resources->db;

            $dbAdapter = Zend_Db::factory($dbConfig->adapter, array(
                        'host' => $dbConfig->params->hostname,
                        'username' => $dbConfig->params->username,
                        'password' => $dbConfig->params->password,
                        'dbname' => $dbConfig->params->dbname
                    ));

            $dbAdapter->getProfiler()->setEnabled(true);
            Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);

            Zend_Registry::set('db', $dbAdapter);

            Zend_Session::start();

            return $dbAdapter;
        }

    }
